import React, { PureComponent } from 'react'

export default class ErrorBound extends PureComponent {

    state = {
        hasError: false
    }

    static getDerivedStateFromError(error) {
        // console.log(error)
        return { hasError: true }
    }

    // componentDidCatch(error, info) {
    //     console.log('记录错误信息：', error, info)
    //     this.setState({ hasError: true })
    // }

    render() {
        if (this.state.hasError) {
            return <h1>Something went wrong.</h1>
        }
        return (
            this.props.children
        )
    }
}

